/**
 * @Title: PreviewPhotoActivity.java
 * @Package: com.jason.bluetooth.fingerprint.ui
 * @Descripton: TODO
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2014年10月22日 下午9:29:16
 * @Version: V1.0
 */
package net.hzlj.platform.enterprise.activity;

import android.os.Bundle;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;

import net.hzlj.platform.enterprise.adapter.PreviewPagerAdapter;
import net.hzlj.rl.zhangjiajie.R;
import net.hzlj.platform.enterprise.widght.TitleBar;

import java.util.List;

import butterknife.BindView;

/**
 * @Description: 图片查看器
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2014年10月22日 下午9:29:16
 */
public class PreviewPhotoActivity extends BaseActivity {


    @BindView(R.id.title_bar)
    TitleBar mTitleBar;
    @BindView(R.id.preview_pager)
    ViewPager mPreviewViewPager;
    private PreviewPagerAdapter mPreviewPagerAdapter;
    private String[] mImages;
    private List<String> list;

    private List<String> mCacheCheckImages;

    @Override
    void handleMessage(BaseActivity activity, Message msg) {

    }

    @Override
    protected void setRootView() {
        super.setRootView();
        setContentView(R.layout.activity_preview_photo);
    }

    @Override
    protected void initTitleBar() {
        super.initTitleBar();
        mTitleBar = (TitleBar) findViewById(R.id.title_bar);
        mTitleBar.bindActivity(this);
        mTitleBar.setOnMainLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        }, "返回", 0, View.VISIBLE);
    }

    @Override
    protected void initWidget() {
        super.initWidget();
    }

    @Override
    protected void initData() {
        super.initData();
        //更新状态栏背景色
        //updateStatusBarBg(R.color.status_bar_photo_bg_color);
        //更新标题栏背景色
        //mTitleBar.setBackBg(R.drawable.status_bar_photo_bg, View.GONE);

        list = getIntent().getStringArrayListExtra("images");
        mCacheCheckImages = getIntent().getStringArrayListExtra("mCacheCheckImages");
        int position = getIntent().getIntExtra("position", 0);
        mPreviewViewPager = (ViewPager) findViewById(R.id.preview_pager);
        mImages = getImages(list);
        mPreviewPagerAdapter = new PreviewPagerAdapter(this, mImages);
        mPreviewViewPager.setAdapter(mPreviewPagerAdapter);
        mPreviewViewPager.setCurrentItem(position);
        mPreviewViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
        updateView(list);
    }

    public void updateView(List<String> images) {
        int curr = mPreviewViewPager.getCurrentItem();
        if (mTitleBar == null) {
            mTitleBar = (TitleBar) findViewById(R.id.title_bar);
            mTitleBar.bindActivity(this);
        }
        if (list != null) {
//			mTitleBar.setUserName((curr+1) + "/" + list.size());
            mTitleBar.setDisplayName((curr + 1) + "/" + list.size());
        }
    }

    private String[] getImages(List<String> list) {
        if (list == null || list.isEmpty() || list.size() < 1) {
            return null;
        }
        String[] image = new String[list.size()];
        return list.toArray(image);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    private class MyOnPageChangeListener implements OnPageChangeListener {

        @Override
        public void onPageScrollStateChanged(int arg0) {
            updateView(list);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {

        }

        @Override
        public void onPageSelected(int arg0) {
            updateView(list);
        }

    }

}
